package cn.ivicar.oss.resource;

import cn.com.carsmart.exception.CarsmartException;
import cn.com.carsmart.ws.util.CacheUtil;
import cn.ivicar.oss.controller.LoginController;
import cn.ivicar.oss.entity.ResponseEntity;
import com.google.inject.Inject;
import com.google.inject.servlet.RequestScoped;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * 用户登录接口
 * Created by Administrator on 2017/5/21.
 */
@Path("user")
@RequestScoped
public class UserResource {
    private static transient final Logger LOGGER = LoggerFactory.getLogger(UserResource.class);

    @Inject
    private LoginController loginController;

    /*
    用户登录
     */
    @Path("login")
    @POST
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public Response login(JSONObject jsonObject) throws CarsmartException {
        String name = jsonObject.optString("name", null);
        String pwd = jsonObject.optString("pwd", null);

        ResponseEntity login = loginController.login(name, pwd);
        return CacheUtil.noCache(Response.ok(login)).build();
    }


}
